﻿using AutoMapper;
using Enferno.Public.Web.Components.Server.ViewModels;
using Enferno.Public.Web.Models;

namespace Enferno.Public.Web.Components.Server.Mappers
{
    public class BasketItemViewModelToBasketItemModelProfile: Profile
    {
        protected override void Configure()
        {
            Mapper.CreateMap<BasketItemViewModel, BasketItemModel>()
                .ForMember(to => to.Price, opts => opts.ResolveUsing<BasketViewModelPriceResolver>());
        }

        public override string ProfileName
        {
            get { return GetType().Name; }
        }
    }

    public class BasketViewModelPriceResolver : ValueResolver<BasketItemViewModel, PriceModel>
    {
        protected override PriceModel ResolveCore(BasketItemViewModel basketItemViewModel)
        {
            return new PriceModel
            {
                Display = basketItemViewModel.DisplayPrice,
                Original = basketItemViewModel.OriginalPrice,
                PricelistId = basketItemViewModel.PriceListId,
                VatRate = basketItemViewModel.VatRate
            };
        }
    }
}
